package com.allwees.bs.module.scm.wf;

import com.baomidou.mybatisplus.core.enums.IEnum;
import com.allwees.core.wf.FsmState;
import com.allwees.core.wf.Transition;

import java.util.Arrays;
import java.util.List;

/**
 * scm 发货单状态机
 *
 * @author mouhaininf
 * @since 2019-12-05
 */
public enum EScmShippingOrderState implements FsmState<EScmShippingOrderState, EScmShippingOrderAction>, IEnum<String> {

    START("Start", false, false) {
        @Override
        public List<Transition<EScmShippingOrderState, EScmShippingOrderAction>> getTransitions() {
            return Arrays.asList(
                    new Transition<>(EScmShippingOrderAction.SUPPLIER_WAIT_ENTER_WAREHOUSE, WAIT_INTO_WAREHOUSE)
            );
        }
    },

    WAIT_INTO_WAREHOUSE("待入仓", true, false) {
        @Override
        public List<Transition<EScmShippingOrderState, EScmShippingOrderAction>> getTransitions() {
            return Arrays.asList(
                    new Transition<>(EScmShippingOrderAction.PLATFORM_ENTERED_WAREHOUSE, COMPLETED),
                    new Transition<>(EScmShippingOrderAction.PLATFORM_ENTERING_WAREHOUSE, PART_INTO_WAREHOUSE),
                    new Transition<>(EScmShippingOrderAction.PLATFORM_ALL_REFUND, REFUND)
            );
        }
    },

    PART_INTO_WAREHOUSE("部分入仓", true, false) {
        @Override
        public List<Transition<EScmShippingOrderState, EScmShippingOrderAction>> getTransitions() {
            return Arrays.asList(
                    new Transition<>(EScmShippingOrderAction.PLATFORM_ENTERED_WAREHOUSE, COMPLETED)
            );
        }
    },

    REFUND("全部退货", false, true),

    CANCELED("Canceled", false, true),

    COMPLETED("已入仓", false, true);

    /**
     * 状态描述
     */
    private String desc;

    private boolean started;

    private boolean ended;

    /**
     * 数据库存储用值
     */
    public String key() {
        return name();
    }

    public String desc() {
        return desc;
    }

    @Override
    public boolean started() {
        return started;
    }

    @Override
    public boolean ended() {
        return ended;
    }

    EScmShippingOrderState(String desc, boolean started, boolean ended) {
        this.desc = desc;
        this.started = started;
        this.ended = ended;
    }

    @Override
    public String getValue() {
        return name();
    }
}
